package com.soladhoc.annonces.server.domain;

import java.util.Date;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import com.soladhoc.annonces.server.service.AppUserDao;


@Entity
public class Annonce extends DatastoreObject {

	private Key<AppUser> owner;
	private String title;
	private Date creationDate = new Date();
	private String text;
	private String description;
	private Boolean published;

	public Boolean getPublished() {
		return published;
	}


	public void setPublished(Boolean published) {
		this.published = published;
	}


	public void setOwner(Key<AppUser> owner) {
		this.owner = owner;
	}


	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}


	public String getDescription() {
		return description;
	}


	public void setDescription(String description) {
		this.description = description;
	}


	public Annonce() {
	}

	
	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getTitle() {
		return title;
	}
	
	public AppUser getOwner() {
		try {
			return new AppUserDao().get(owner);
		} catch (EntityNotFoundException e) {
			throw new RuntimeException(e);
		}
	}


	public void setOwner(AppUser owner) {
		this.owner = new AppUserDao().key(owner);
	}


}
